#! /usr/bin/python

#    <PyAPI helps to use api on diferent platforms.>
#    Copyright (C) 2011  Regimantas Baublys
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#    Email: regtech0@gmial.com


import os, commands

def clear():
 if os.name == "posix":
  # Unix/Linux/MacOS/BSD/etc
  os.system('clear')
 elif os.name in ("nt", "dos", "ce"):
  # DOS/Windows
  os.system('CLS')
 else:
  # Fallback for other operating systems.
  print '\n' * 100


def shelloutput(shellinput):
  if os.name == "posix":
    # Unix/Linux/MacOS/BSD/etc
    x = commands.getstatusoutput(shellinput)
    a = x[1:]
    b = str(a)
    c = b.replace(",", "")
    d = c.replace("(","")
    e = d.replace(")","")
    f  = e.replace(" ", "")
    g  = e.replace("'", "")
    return g
  elif os.name in ("nt", "dos", "ce"):
    # DOS/Windows
    z = os.popen(shellinput + " 2>&1")
    h = z.read()
    z.close()
    j = str(h)
    return j
    

def move_mouse(x,y):
  if os.name == "posix":
    # Unix/Linux/MacOS/BSD/etc
    from ctypes import cdll
    dll = cdll.LoadLibrary('libX11.so')
    d = dll.XOpenDisplay(None)
    root = dll.XDefaultRootWindow(d)
    dll.XWarpPointer(d,None,root,0,0,0,0,x,y)
    dll.XCloseDisplay(d)
  elif os.name ==("nt"):
    from ctypes import *
    user32 = windll.user32
    user32.SetCursorPos(x, y)


